<template>
  <div class="run-knife-container">
    <h1>纯绿跑刀，可直播</h1>
    <!-- 选择框 -->
    <div class="slider-container">
      <div class="slider-label">选择哈夫币数量</div>
      <div class="button-group">
        <a-button 
          v-for="option in coinOptions" 
          :key="option.value"
          :type="coinValue === option.value ? 'primary' : 'default'"
          @click="selectCoin(option.value)"
          class="coin-button"
        >
          {{ option.label }}
        </a-button>
      </div>
      <div class="slider-value">200万一小时计，客服会拉群，与打手沟通
        <div class="price-value">
          价格：¥{{ price }} 元
        </div>
        <div class="time-value">
          预计用时：{{ time }} 小时
        </div>
        <!-- 支付链接 -->
        <div class="payment-section">
          <a-button type="primary" size="large"  @click="handlePayment" :disabled="price <= 0" class="pay-button">
            立即支付
          </a-button>
        </div>
      </div>
    </div>

    <!-- 二维码弹窗 -->
    <a-modal
      v-model:visible="qrModalVisible"
      title="扫码进入小程序"
      :footer="null"
      centered
      width="400px"
      class="qr-modal"
    >
      <div class="qr-content">
        <div class="qr-info">
          <!-- <p class="qr-title">扫码支付 ¥{{ price }} 元</p> -->
          <p class="qr-subtitle">购买 {{ formatCoinValue(coinValue) }} 哈夫币</p>
        </div>
        <div class="qr-wrapper">
          <img src="/images/hfbwxqr.png" alt="支付二维码" class="qr-image" />
        </div>
        <p class="qr-description">打开微信小程序进行购买</p>
      </div>
    </a-modal>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue';

// 当前值
const coinValue = ref(10000000); // 默认为1000万

// 价格（1000万等于80元）
const price = ref(80);

// 二维码弹窗控制
const qrModalVisible = ref(false);

// 计算预计用时（200万/小时）
const time = computed(() => {
  return (coinValue.value / 2000000).toFixed(2);
});

// 哈夫币选项
const coinOptions = [
  { value: 10000000, label: '1000万' },
  { value: 20000000, label: '2000万' },
  { value: 30000000, label: '3000万' },
  { value: 40000000, label: '4000万' },
  { value: 50000000, label: '5000万' },
  { value: 60000000, label: '6000万' },
  { value: 70000000, label: '7000万' },
  { value: 80000000, label: '8000万' },
  { value: 90000000, label: '9000万' },
  { value: 100000000, label: '1亿' }
];

// 选择哈夫币数量
const selectCoin = (value) => {
  coinValue.value = value;
  calculatePrice();
};

// 格式化哈夫币数值显示
const formatCoinValue = (value) => {
  if (value >= 100000000) {
    return (value / 100000000).toFixed(2) + '亿';
  } else if (value >= 10000) {
    return (value / 10000).toFixed(0) + '万';
  } else {
    return value;
  }
};

// 计算价格（1000万等于80元）
const calculatePrice = () => {
  price.value = (coinValue.value / 10000000) * 80;
};

// 处理支付
const handlePayment = () => {
  // 显示二维码弹窗
  qrModalVisible.value = true;
};

// 组件挂载时计算初始价格
onMounted(() => {
  calculatePrice();
});
</script>

<style scoped lang="scss">
.run-knife-container {
  h1 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
  }
  
  .slider-container {
    margin: 30px;
    padding: 30px;
    text-align: center;
    background: rgba(84, 100, 117, 0.344);
    border-radius: 22px;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.5);
    
    .slider-label {
      font-size: 30px;
      font-weight: 500;
      color:rgba(255, 255, 255, 0.664);
      margin-bottom: 30px;
    }
    
    .button-group {
      display: flex;
      justify-content: center;
      flex-wrap: wrap;
      gap: 10px;
      margin-bottom: 15px;
      
      .coin-button {
        height: 50px;
        width: 100px;
        font-size: 20px;
        padding: 0 10px;
        border: 1px solid seagreen;
        border-radius: 15px;
        box-shadow: 0 4px 12px rgba(79, 172, 254, 0.3);
        
        &:hover {
          transform: translateY(-2px);
          box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }
      }
    }
    
    .slider-value {
      text-align: center;
      font-size: 18px;
      font-weight: 600;
      color: #00000000;
      
      .price-value {
        font-size: 20px;
        color: yellow;
        font-weight: bold;
      }
      
      .time-value {
        font-size: 20px;
        color: yellow;
        font-weight: bold;
        margin: 20px 0;
      }
    }
  }
  
  .value-display {
    text-align: center;
    margin: 30px 0;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 12px;
  }
}

// 二维码弹窗样式
:deep(.qr-modal .ant-modal-content) {
  border-radius: 16px;
  overflow: hidden;
}

:deep(.qr-modal .ant-modal-header) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-bottom: none;
  
  .ant-modal-title {
    color: white;
    font-weight: 600;
    text-align: center;
  }
}

.qr-content {
  text-align: center;
  padding: 20px 10px;
  
  .qr-info {
    margin-bottom: 20px;
    
    .qr-title {
      font-size: 18px;
      font-weight: 600;
      color: #333;
      margin-bottom: 8px;
    }
    
    .qr-subtitle {
      font-size: 14px;
      color: #666;
      margin: 0;
    }
  }
  
  .qr-wrapper {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    
    .qr-image {
      width: 200px;
      height: 200px;
      border-radius: 12px;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
      transition: transform 0.3s ease;
      
      &:hover {
        transform: scale(1.02);
      }
    }
  }
  
  .qr-description {
    font-size: 14px;
    color: #888;
    margin: 0;
    margin-top: 16px;
  }
}
</style>